package com.uy.cuantoconocesdeuruguay.utiles;

import com.uy.cuantoconocesdeuruguay.MainActivity;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

public class ApplicationUtils {
	public static final String FACEBOOK_LOGIN_WORKAROUND = "com.uy.cuantoconocesdeuruguay.utiles.FACEBOOK_LOGIN_WORKAROUND";
	public static void restartApplication(Activity activity) {
		Intent mStartActivity = new Intent(activity.getApplicationContext(), MainActivity.class);
		int mPendingIntentId = 123456;
		PendingIntent mPendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
		AlarmManager mgr = (AlarmManager)activity.getSystemService(Context.ALARM_SERVICE);
		mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
		System.exit(0);
	}
	public static void restartApplicationFacebookException(Activity activity) {
		Intent mStartActivity = new Intent(activity.getApplicationContext(), MainActivity.class);
		mStartActivity.putExtra(FACEBOOK_LOGIN_WORKAROUND, true);
		int mPendingIntentId = 123456;
		PendingIntent mPendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
		AlarmManager mgr = (AlarmManager)activity.getSystemService(Context.ALARM_SERVICE);
		mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
		System.exit(0);
	}
	public static void pressHomeButton(Activity activity) {
		Intent backtoHome = new Intent(Intent.ACTION_MAIN);
        backtoHome.addCategory(Intent.CATEGORY_HOME);
        backtoHome.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        activity.startActivity(backtoHome);
	}

}
